package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyCatalog;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.query.StrategyCatalogQuery;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService{
    @Autowired
    private StrategyCatalogMapper strategyCatalogMapper;


    @Override
    public PageInfo selectForList(StrategyCatalogQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCatalog> list = strategyCatalogMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        if(strategyCatalog.getSequence()==null){
            strategyCatalog.setSequence(
                    strategyCatalogMapper.selectAutoSequence(
                        strategyCatalog.getStrategy().getId()) + 1);
        }
        if(strategyCatalog.getId()==null){
            strategyCatalogMapper.insert(strategyCatalog);
        }else{
            strategyCatalogMapper.updateByPrimaryKey(strategyCatalog);
        }
    }

    @Override
    public List<StrategyCatalog> selectCatalogByStrategyId(Long strategyId) {
        return strategyCatalogMapper.selectCatalogBystrategyId(strategyId);
    }

    @Override
    public List<StrategyCatalog> getCatalogsByStrategyId(Long strategyId) {
        return strategyCatalogMapper.selectCatalogBystrategyId(strategyId);
    }


}
